<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

    <button>发起请求</button>
    <div></div>
    <!-- <script src="./03.Promise基本用法.js"></script> -->
    <script src="./Promise封装请求方式.js"></script>

    <script>
        const btn = document.querySelector('button')
        btn.addEventListener('click', function () {
            const div = document.querySelector('div')
            const resGet = harryAjax({ method: 'GET', url: 'http://ajax-base-api-t.itheima.net/api/getbooks' })
            const resPost = harryAjax({
                method: 'POST',
                url: 'http://ajax-base-api-t.itheima.net/api/post',
                data: {
                    bookname: '11',
                    author: '22',
                    publisher: '33',
                }
            })
            const promiseArr = [resGet, resPost]
            Promise.all(promiseArr).then(res => {
                console.log(res)
                div.innerHTML = '我是界面'
            })
                .catch(err => {
                    div.innerHTML = err
                })
        })


    </script>
</body>

</html>